﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Microserve.TeleEye.Common.Utility;

namespace Microserve.TeleEye.Data
{
    public class SectionHome
    {
        public XmlDocument GetSideMenu(string sideMenuSource)
        {
            XmlDocument doc = new XmlDocument();
            if (!string.IsNullOrEmpty(sideMenuSource))
            {
                doc.Load(sideMenuSource);
            }

            return doc;
        }

        public XmlDocument GetFeaturedProduct(string featuredProductSource)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(featuredProductSource);
            return doc;
        }

        public string GetSectionTitle(string sectionSource)
        {
            string sectionTitle = string.Empty;

            XmlDocument doc = new XmlDocument();
            doc.Load(sectionSource);
            sectionTitle = XmlDocumentHelper.GetAttributeValue(
                doc.SelectSingleNode("section"), "titleLeft");
            return sectionTitle;
        }

        public string GetSectionName(string sectionSource)
        {
            string sectionTitle = string.Empty;

            XmlDocument doc = new XmlDocument();
            doc.Load(sectionSource);
            sectionTitle = XmlDocumentHelper.GetAttributeValue(
                doc.SelectSingleNode("section"), "name");
            return sectionTitle;
        }

        public string GetSectionContent(string sectionSource)
        {
            string sectionContent = string.Empty;

            XmlDocument doc = new XmlDocument();
            doc.Load(sectionSource);

            XmlNode content = doc.SelectSingleNode("section/maincontent");

            if (content != null)
            {
                sectionContent = content.InnerXml;
            }

            return sectionContent;
        }

        public string GetSectionSubtitle(string sectionSource)
        {
            string sectionTitle = string.Empty;

            XmlDocument doc = new XmlDocument();
            doc.Load(sectionSource);            
            sectionTitle = XmlDocumentHelper.GetAttributeValue(
                doc.SelectSingleNode("section"), "titleRight");
            return sectionTitle;
        }

        public XmlNode GetParentSection(string source)
        {            
            XmlDocument doc = new XmlDocument();
            doc.Load(source);

            return doc.SelectSingleNode("section/parentsection");
        }

        public string GetSectionAbstract(string sectionSource)
        {
            string sectionTitle = string.Empty;

            XmlDocument doc = new XmlDocument();
            doc.Load(sectionSource);
            XmlNode node = doc.SelectSingleNode("section/abstract");
            if (node != null)
            {
                sectionTitle = node.InnerXml;
            }

            return sectionTitle;
        }
    }
}
